﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zeus.Thunder.Core;
using CsharpTrainer.Model.Entities;
using System.Runtime.Serialization;
using System.IO;

namespace SharpTrainer.Serialization
{
    class DataContractXmlSerializeTest : ITestCase
    {
        public void Run()
        {
            Person p = new Person { Name = "Stacey", Age = 30 };

            var ds = new DataContractSerializer(typeof(Person));
            using (Stream s = File.Create("person.xml"))
                ds.WriteObject(s, p); // Serialize

            Person p2;
            using (Stream s = File.OpenRead("person.xml"))
                p2 = (Person)ds.ReadObject(s); // Deserialize

            Console.WriteLine(p2.Name + " " + p2.Age); // Stacey 30
        }
    }
}
